# 存档具体要实现的代码  属于worker区域
import logging

from celery_tasks.main import app
from meiduo_mall.utils.yuntongxun.sms import CCP

logger = logging.getLogger('django')

@app.task(name='send_sms_code')
def send_sms_code(mobile, sms_code):
    ccp = CCP()
    try:
        result = ccp.send_template_sms(mobile, [sms_code, 5], 1)
    except Exception as e:
        logger.error('短信发送异常[mobile：%s ,message:%s]' % (mobile, e))
    else:
        if result == 0:
            # 返回0 表示发送短信成功
            logger.info('短信发送成功[mobile：%s ,sms:%s]' % (mobile, sms_code))
        else:
            # 返回-1 表示发送失败
            logger.error('短信发送异常[mobile：%s ]' % mobile)
